/**
 * 
 */
package durak.server.control;

import java.util.HashSet;
import java.util.Set;

import durak.server.model.GameDesc;

/**
 * @author ariet
 *
 */
public class GamesManager {

	private Set<Game> activeGames;
	
	public GamesManager() {
		activeGames = new HashSet<Game>();
	}

	public Set<Game> getActiveGames() {
		return activeGames;
	}

	public Set<GameDesc> getGamesDescriptions() {
		Set<GameDesc>	games = new HashSet<GameDesc>();

		for (Game game : activeGames) {
			games.add(game.getGameDescription());
		}
		return games;
	}
	
	public Game getGame(String gameName) {
		for (Game game : activeGames) {
			if(game.getName().equalsIgnoreCase(gameName))
				return game;
		}
		return null;
	}
	
	public boolean addGame(Game game) {
		if(isGameExists(game.getName()))
			return false;
		return activeGames.add(game);
	}
	
	boolean removeGame(String gameName) {
		if(isGameExists(gameName))
			return false;
		return activeGames.remove(getGame(gameName));
	}
	
	
	public boolean isGameExists(String gameName) {
		for (Game game : activeGames) {
			if(game.getName().equalsIgnoreCase(gameName))
				return true;
		}
		return false;
	}
	
	
}
